<?php
class Codetype extends AppModel
{
	var $name = 'Codetype';
    var $primaryKey = 'id';
    var $hasMany = array (
			'Codevalue' => array (
			'className' => 'Codevalue',
			'foreignKey' => 'codetype_id',
			'order' => 'Codevalue.sort asc',
    		'dependent' => true
		)
	); 
	
	function getTechnologyType($cvalue){
		$objtypes= $this->findAllByType($cvalue);
		if($objtypes){
			foreach ($objtypes[0]["Codevalue"] as $objtype){
		 		$options[$objtype['id']]=$objtype['value'];
			}
		}
		return $options;
	}
	//获取子类列表
	function getCValues($cvalue,$isflag=null)
	{
		$Constant=classregistry::init('Constant');
		$Phase=$Constant->Phase;
		$Registr=$Constant->Registr;
		$Declare=$Constant->Declare;
	 	$NRegistr=$Constant->NRegistr;
		$WRegistr=$Constant->WRegistr;
		$Forbid = $Constant->Forbid;
		$objtypes= $this->findAllByType($cvalue);
		$options=array();
		if($isflag=="all")
		{
			$options['']="全部所属产业";
		}
		if(empty($isflag)){
			$str="";
			if($cvalue==$Phase)
			{
				$str=__('Phase',true);
			}
			else if($cvalue==$Registr)
			{
				$str=__('Sub Type',true);
			}
			else if($cvalue==$NRegistr || $cvalue==$WRegistr || $cvalue==$Declare)
			{
				$str=__('Sub Phase',true);
			}
			else if($cvalue == $Forbid){
				$str=__('Forbid',true);
			}
			$options['']=__('Please select',true).$str;
		}
		if($objtypes){
			foreach ($objtypes[0]["Codevalue"] as $objtype){
		 		$options[$objtype['id']]=$objtype['value'];
			}
		}
		return $options;
	}
	function getSubType($cvalue,$fh="└─",$flag=null,$select="请选择部门"){
		$objtypes= $this->findAllByType($cvalue);
		$options=array();
		$options['']=$select;
		foreach ($objtypes[0]["Codevalue"] as $objtype){
			$tvalue=$objtype['value'];
	 		$options[$objtype['id']]=$tvalue;
	 		$subtype=$this->findAllByType($tvalue);
	 		if($subtype){
	 			foreach ($subtype[0]["Codevalue"] as $stype){
	 				$tname="";
	 				if($flag){
	 					$tname=$tvalue;
	 				}
	 				$options[$stype['id']]=$tname.$fh.$stype['value'];
	 			}
	 		}
		}
		return $options;
	}
	//获取美元汇率
	function getrate(){
		$exchangeEate=classregistry::init('Constant')->ExchangeEate;
		$objrates=$this->getCValues($exchangeEate,1);
		$rate=0;
		$i=0;
		foreach ($objrates as $rates){
			if($i==0){
				$rate=$rates;
			}
			$i++;
		}
		return ($rate+0);
	}
	//注册资金转换查看
	function getcapital(){
		$rate=$this->getrate();
		$column="(case cap_type when '1' then capital*($rate) else capital end) as capital";
		return $column;
	}
	//获取企业划分区域
	function getMenu($html,$actions){
		$forbid=classregistry::init('Constant')->Forbid;
		$objmenu=$this->getCValues($forbid,1);
		if(!empty($_GET['forbid'])){
			echo '<ul>';
		}else if($actions=="carrierin"){
			echo '<ul>';
		}
		else{
			echo '<ul style="display:none;">';
		}
		foreach($objmenu as $key=>$menu)
		{  
			$selected="";
			if($_GET['forbid']==$key){
				$selected = "selected";
			}
			 echo '<li>';
			 echo $html->link($menu,"/searchs/carrierin?forbid=".$key,array("class"=>$selected));
			 echo '</li>';
		}
		echo '</ul>';
	}
	
	/**
	* 获取指定code类型的ID
	* @param: $father_name Codetype的名字,如：申报状态
	* 		  $type_name  Codevalue的名字，如：已立项
	* @Return: String
	* @author cyjiang
	*/
	function findCodeValueID($father_name,$type_name)
	{
		$types = $this->getCValues($father_name);
		foreach($types as $key=>$type)
		{
			if($type_name == $type)
				return $key;
		}
		return "";
	}
	
	
	
}
?>